package com.memory.monitor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.memory.monitor.annotation.AuthCheck;
import com.memory.monitor.common.BaseResponse;
import com.memory.monitor.common.DeleteRequest;
import com.memory.monitor.common.ResultUtils;
import com.memory.monitor.constant.UserConstant;

import com.memory.monitor.model.dto.job.JobAddRequest;
import com.memory.monitor.model.dto.job.JobQuerryRequest;
import com.memory.monitor.model.dto.job.JobUpdateRequest;
import com.memory.monitor.model.entity.Job;
import com.memory.monitor.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/job")
@Slf4j
public class JobController {
    @Resource
    private JobService jobService;

    /**
     * 分页获取信息
     *
     * @param jobQuerryRequest
     * @return
     */
    @PostMapping("/list/page")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Page<Job>> listByPageJob(@RequestBody JobQuerryRequest jobQuerryRequest) {
        long current = jobQuerryRequest.getCurrent();
        long size = jobQuerryRequest.getPageSize();
        // Page<User> userPage = userService.page(new Page<>(current, size),
        //         userService.getQueryWrapper(userQueryRequest));
        Page<Job> userPage = jobService.page(new Page<>(current, size));
        return ResultUtils.success(userPage);
    }

    /**
     * 增加信息  返回id
     * @param jobAddRequest
     * @return
     */
    @PostMapping("/add")
    public BaseResponse<Long> addJob(@RequestBody JobAddRequest jobAddRequest){
        Long id = jobService.addJob(jobAddRequest);
        return ResultUtils.success(id);
    }
    /**
     * 修改信息 返回boolean
     *
     * @param jobUpdateRequest

     * @return
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateJob(@RequestBody JobUpdateRequest jobUpdateRequest){
        Boolean result= jobService.updateJob(jobUpdateRequest);
        return ResultUtils.success(result);
    }

    /**
     * 删除信息 返回boolean
     *
     * @param deleteRequest

     * @return
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteJob(@RequestBody DeleteRequest deleteRequest){
        Boolean result = jobService.deleteJob(deleteRequest);
        return ResultUtils.success(result);
    }

}